<?php
    
header("Conent-Type:text/html;charset=utf-8");  //设置编码

$q = isset($_GET["q"]) ? intval($_GET["q"]) : '';
 
if(empty($q)) {
    echo '请选择一个网站';
    exit;
}

//数据库连接
$conn = new mysqli("localhost", "root", "gcy888999", "cainiao");
mysqli_set_charset($conn, 'utf8');

//检测连接
if(mysqli_connect_error()) {
    die("连接失败: " . $conn->connect_error);
}

//设置编码，防止中文乱码
mysqli_set_charset($conn, "utf8");

$sql="SELECT * FROM websites WHERE id = ".$q;
$result = mysqli_query($conn, $sql);

echo "<table border='1'>
<tr>
<th>ID</th>
<th>网站名</th>
<th>网站地址</th>
<th>Alexa 排名</th>
<th>国家</th>
</tr>";

while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" .$row['name']. "</td>";
    echo "<td>" .$row["url"]. "</td>";
    echo "<td>" .$row["alexa"] ."</td>";
    echo "<td>" .$row["country"] . "</td>";
    echo "</tr>";
};

echo "</table>";
mysqli_close($conn);
